<template>
  <el-cascader :value="value" :options="options" :props="props" separator="-" @change="changeValue" />
</template>

<script>
import { getDepartmentApi } from '@/api/department'
import { transListToTreeData } from '@/utils'
export default {
  props: {
    value: {
      type: Number, // 存储的是部门的id  3 4 5
      default: null
    }
  },
  data() {
    return {
      props: {
        value: 'id',
        label: 'name'
      },
      options: []
    }
  },
  created() {
    this.getDepartment()
  },
  methods: {
    async getDepartment() {
      this.options = transListToTreeData(await getDepartmentApi(), 0)
    },
    changeValue(list) {
      if (list.length) {
        this.$emit('input', list[list.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>

<style scoped lang="scss">

</style>
